﻿using System;
using System.Windows.Data;

namespace DDU.Converters
{
    public class ValueEqualsParameterToBooleanConverter : IValueConverter
    {
        public object DefaultValue { get; set; }

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if ((parameter is string) && (value != null))
            {
                return Equals(value.ToString(), parameter);
            }

            return Equals(value, parameter);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var boolValue = value as bool?;
            if (boolValue.HasValue && boolValue.Value)
                return parameter;

            return this.DefaultValue;
        }

        #endregion
    }
}